package com.ynding.cloud.auth.server.admin.controller;


import com.ynding.cloud.auth.api.admin.domain.MenuDO;
import com.ynding.cloud.auth.server.admin.service.IMenuService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 这是一个只要登录就能访问的Controller
 * 主要用来获取一些配置信息
 * @author ynding
 *
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/config")
public class ConfigController {
    private final IMenuService menuService;

    @GetMapping("/sysMenu")
    @ApiOperation(value = "系统菜单", produces = "application/json")
    public List<MenuDO> sysMenu() {
        return menuService.findAll();
    }

    @GetMapping("/user")
    @ApiOperation(value = "当前用户", produces = "application/json")
    public Object currentUser() {
        return SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }
}
